﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Production_Set.API.Application.Commands.Orderers;
using Production_Set.API.Application.Commands.Procurement;
using Production_Set.API.Application.Commands.Supplier;
using Production_Set.API.Application.Commands.Technology;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Set.API.Controllers.SU
{
    /// <summary>
    /// 生产-工艺，供应商，采购/委外
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProducManagementController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ProducManagementController> logger;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="logger"></param>
        public ProducManagementController(IMediator mediator, ILogger<ProducManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }

        /// <summary>
        /// 工艺路线添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddProcessRoute(ProcessRouteCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("工艺路线添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("工艺路线添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 供应商添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddSupplier(SupplierCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("供应商添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("供应商添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 供应商删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DelSupplier(SupplierDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("供应商删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("供应商删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 联系人信息删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DelContactPersons(ContactPersonsDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("联系人信息删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("联系人信息删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 银行删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DelBanks(BanksDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("银行删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("银行删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 供应商修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdateSupplier(SupplierUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("供应商修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("供应商修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 联系人信息修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdateContactPersons(ContactPersonsUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("联系人信息修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("联系人信息修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 银行修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> UpdateBanks(BanksUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("银行修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("银行修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 供应商导入
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SuppliersImport(SuppliersImportCommand cmd)
        {
            try
            {
                logger.LogInformation("供应商导入");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("供应商导入失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 采购/委外订单
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddProcurement(PurchasingsCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("采购/委外订单");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("采购/委外订单失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 采购/委外订单删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DelPurchasings(PurchasingsDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("采购/委外订单删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("采购/委外订单删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 采购/委外订单反填
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> PurchasingsSelId(PurchasingsSelIdCommand cmd)
        {
            try
            {
                logger.LogInformation("采购/委外订单反填");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("采购/委外订单反填失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 采购/委外订单修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> PurchasingsUpdate(PurchasingsUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("采购/委外订单修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("采购/委外订单修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 订单行添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> OrderLinesAdd(OrderLinesAddCommend cmd)
        {
            try
            {
                logger.LogInformation("订单行修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("订单行修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 订单行修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> OrderLinesUpdate(OrderLinesUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("订单行修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("订单行修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 付款计划添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> PaymentPlansCreateCommand(PaymentPlansCreateCommand cmd)
        {
            try
            {
                logger.LogInformation("付款计划添加");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("付款计划添加失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 付款计划修改
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<Result> PaymentPlansUpdate(PaymentPlansUpdateCommand cmd)
        {
            try
            {
                logger.LogInformation("付款计划修改");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("付款计划修改失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 订单行删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> OrderLinesDelete(OrderLinesDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("订单行删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("订单行删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 付款计划删除
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> PaymentPlansDelete(PaymentPlansDeleteCommand cmd)
        {
            try
            {
                logger.LogInformation("付款计划删除");
                return await mediator.Send(cmd);
            }
            catch (Exception ex)
            {
                logger.LogError("付款计划删除失败" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 审批
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> GetApprovalStatus(ApprovalStatusCommand cmd)
        {
            try
            {
                logger.LogInformation("审批成功");
                return await mediator.Send(cmd);
            }
            catch (Exception)
            {
                logger.LogError("审批失败");
                throw;
            }
        }

        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> ApprovalStatusSubmit(ApprovalStatusSubmitCommand cmd)
        {
            try
            {
                logger.LogInformation("提交成功");
                return await mediator.Send(cmd);
            }
            catch (Exception)
            {
                logger.LogError("提交失败");
                throw;
            }
        }

        /// <summary>
        /// 驳回
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> ApprovalStatusOverrule(ApprovalStatusOverruleCommand cmd)
        {
            try
            {
                logger.LogInformation("驳回成功");
                return await mediator.Send(cmd);
            }
            catch (Exception)
            {
                logger.LogError("驳回失败");
                throw;
            }
        }
    }
}
